home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_pcdp / adas / peter.ada < prev    next >
Text File  |  1996-01-30  |  849b  |  43 lines

  1. with Text_IO; use Text_IO;
  2. procedure Peter is
  3.   pragma Time_Slice(0.01);
  4.  
  5.   C1, C2: Integer := 1;
  6.   Last:   Integer := 1;
  7.  
  8.   pragma Volatile(C1);
  9.   pragma Volatile(C2);
  10.   pragma Volatile(Last);
  11.  
  12.   task T1;
  13.   task body T1 is
  14.   begin
  15.     loop
  16.       Put_Line("Task 1 idling");
  17.       C1 := 1;
  18.       Last := 1;
  19.       Put_Line("Task 1 trying to enter");
  20.       loop exit when (C2 = 0)  or  (Last /= 1); end loop;
  21.       Put_Line("Task 1 critical section");
  22.       C1 := 0;
  23.     end loop;
  24.   end T1;
  25.  
  26.   task T2;
  27.   task body T2 is
  28.   begin
  29.     loop
  30.       Put_Line("Task 2 idling");
  31.       C2 := 1;
  32.       Last := 2;
  33.       Put_Line("Task 2 trying to enter");
  34.       loop exit when (C1 = 0) or (Last /= 2); end loop;
  35.       Put_Line("Task 2 critical section");
  36.       C2 := 0;
  37.     end loop;
  38.   end T2;
  39.  
  40. begin
  41.   null;
  42. end Peter;
  43.